<template>
  <div class="home">
    <van-nav-bar sticky :title="$route.meta.title" />
    <van-search
      v-model="value"
      placeholder="搜索医生、医院、科室等"
      @focus="goSearch"
    />
    <van-swipe :autoplay="3000">
      <van-swipe-item v-for="item in images" :key="item.id">
        <img v-lazy="item.image" />
      </van-swipe-item>
    </van-swipe>
    <div class="recommendDoctor">
      <div class="header">
        <div class="recommend">推荐医生</div>
        <div class="more" @click="getmoredoctor">更多&nbsp;&gt;</div>
      </div>
      <div class="doctorInfo list">
        <div class="doctor" ref="doctor">
          <van-card
            v-for="item in recommDot"
            :key="item.id"
            thumb="https://kang-1305144775.cos.ap-nanjing.myqcloud.com/heade.jpg"
          >
            <template #desc>
              <div class="info">{{ item.Dname }}&nbsp;{{ item.Dpro }}</div>
              <div class="info">
                {{ item.hospital }}&nbsp;{{ item.Doffice }}
              </div>
              <div class="info">擅长:{{ item.Dspecialise }}</div>
            </template>
          </van-card>
        </div>
      </div>
    </div>
    <div class="recommendDoctor">
      <div class="header">
        <div class="recommend">推荐医院</div>
        <div class="more" @click="getmorehospital">更多&nbsp;&gt;</div>
      </div>
      <div class="hospitals">
        <div class="hospital" v-for="item in hospitals" :key="item.id">
          <dl>
            <dt>
              <img v-lazy="item.pic" alt="" />
            </dt>
            <dd>{{ item.Hname }}</dd>
          </dl>
        </div>
      </div>
    </div>
    <div class="hospitalRank">
      <div class="header">医院排行</div>
      <div class="hospital_list">
        <van-card v-for="item in hospitals" :key="item.id" :thumb="item.pic">
          <template #desc>
            <div class="name">
              {{ item.Hname }}
            </div>
            <div class="Grade">
              {{ item.Grade }}
            </div>
          </template>
        </van-card>
      </div>
    </div>
    <div class="patient">
      <van-nav-bar :title="$route.meta.title" />
      <div class="keshi">
        <div class="register">
          <div class="title">热门科室</div>
          <div class="more">
            更多
            <i>&gt;</i>
          </div>
        </div>
        <van-grid :column-num="5">
          <van-grid-item
            v-for="value in 15"
            :key="value"
            icon="photo-o"
            text="文字"
          />
        </van-grid>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  components: {
  },
  data: () => ({
    value: '',
    images: [],
    recommDot: [],
    pos: [],
    hospitals: [],
    pageSize: 4,
    pageNo: 1
  }),
  methods: {
    goSearch () {
      this.$router.push('/search')
    },
    getmoredoctor () {
      this.$router.push('/home/moredoctor')
    },
    getmorehospital () {
      this.$router.push('/home/morehospital')
    },
    async getLunbo () {
      const res = await this.$http.getLunbo()
      this.images = res.data
    },
    async getRecommDot () {
      const res = await this.$http.getRecommDot({
        pageSize: this.pageSize,
        pageNo: this.pageNo
      })
      this.recommDot = res.data
    },
    async getRecommHot () {
      const res = await this.$http.getRecommHot({
        pageSize: this.pageSize,
        pageNo: this.pageNo
      })
      this.hospitals = res.data
    },
    huadong () {
      const th = this
      Object.values(this.$refs).forEach(function (el, index) {
        el.addEventListener('touchstart', function (e) {
          const start = e.touches[0].pageX
          el.ontouchmove = function (e) {
            const step = e.touches[0].pageX - start
            if (th.pos[index] === undefined) {
              th.pos[index] = 0
            }
            if (th.pos[index] + parseInt(step) > 0) {
              el.style.left = '0px'
            } else if (th.pos[index] + parseInt(step) < document.querySelector('.list').offsetWidth - el.offsetWidth) {
              el.style.left = document.querySelector('.list').offsetWidth - el.offsetWidth + 'px'
            } else {
              el.style.left = th.pos[index] + parseInt(step) + 'px'
            }
          }
          el.ontouchend = function () {
            th.pos[index] = parseInt(el.style.left)
          }
        })
      })
    }
  },
  created () {
    this.getLunbo()
    this.getRecommDot()
    this.getRecommHot()
  },
  mounted () {
    this.huadong()
  }
}
</script>
<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
}
.keshi {
  .register {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #fff;
    margin-top: 9px;
    height: 16px;
    padding: 0 6px;
    box-sizing: border-box;
    border: 0.3px solid #eee;
    .title {
      font-size: 7px;
      height: 10px;
      line-height: 10px;
      padding-left: 2px;
      font-weight: 600;
      border-left: 2px solid rgb(5, 165, 13);
    }
    .more {
      font-size: 6px;
      color: rgb(179, 174, 174);
    }
  }
}
.home {
  background: #a8a6a6;
  box-sizing: border-box;
  padding-top: 20px;
  .van-nav-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
  }
  .van-search__content {
    border-radius: 10px;
  }
  .van-swipe {
    width: 100%;
    height: 80px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .header {
    background-color: #fff;
    display: flex;
    box-sizing: border-box;
    padding: 0 6px;
    height: 15px;
    line-height: 15px;
    justify-content: space-between;
    .recommend {
      font-size: 8px;
      font-weight: 700;
    }
  }
  .doctorInfo {
    width: 100%;
    position: relative;
    height: 44px;
    overflow: hidden;
    .doctor {
      height: 100%;
      // width: 1000%;
      display: flex;
      left: 0;
      bottom: 0;
      position: absolute;
      .van-card {
        // float: left;
        width: 105px;
        margin-top: 0;
        .van-image {
          border-radius: 50%;
        }
      }
    }
  }
  .van-card__header {
    width: 100px;
  }
  .van-card__content {
    .info {
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 1;
      overflow: hidden;
      margin-top: 4px;
      color: #999;
    }
  }
  .hospitals {
    display: flex;
    background: #fff;
    dl {
      width: 50px;
      margin-right: 10px;
      dt {
        width: 40px;
        img {
          width: 100%;
          height: 100%;
        }
      }
      dd {
        color: #999;
        font-size: 7px;
      }
    }
  }
  .hospitalRank {
    box-sizing: border-box;
    padding-top: 10px;
    background-color: #fff;
    .header {
      height: 15px;
      font-size: 8px;
      font-weight: 700;
    }
  }
}
</style>
